A refresher on coding best practices…
mutate() vs summarise()Bar plots are typically reserved for displaying frequencies
# A tibble: 4 × 3
geography mean_price_diff sd_price_diff
<fct> <dbl> <dbl>
1 San Francisco 0.719 0.334
2 San Diego 0.685 0.211
3 Sacramento 0.578 0.270
4 Los Angeles 0.528 0.188
library(RColorBrewer)
library(scales)
diff_summary |>
ggplot(aes(x = mean_price_diff,
y = geography,
fill = geography)
) +
geom_bar(stat = "identity") +
labs(
title = "Difference in Price between Organic and Conventional Avocados",
y = "") +
theme_minimal() +
theme(legend.position = "none") +
scale_fill_brewer(palette = "Dark2") +
scale_x_continuous(name = "",
labels = scales::label_dollar()
)Read more about Cleveland Dot Plots
diff_summary |>
arrange(desc(mean_price_diff)) |>
ggplot(aes(x = mean_price_diff,
y = geography,
fill = geography)
) +
geom_segment(aes(xend = 0,
yend = geography)
) +
geom_point() +
labs(title = "Difference in Price between Organic and Conventional Avocados",
y = "") +
theme_minimal() +
theme(legend.position = "none") +
scale_fill_brewer(palette = "Dark2") +
scale_x_continuous(name = "",
labels = scales::label_dollar()
)What is wrong with this code?
What is wrong with this code?
What is the difference between facet_wrap() and facet_grid()?
When should you use facet_grid()?
Version Control
A structured way for tracking changes to files over the course of a project.
Makes it easy to have multiple people working on the same files at the same time.
You can host a URL of fun things (like the class text, these slides, a personal website, etc.) with GitHub pages.
Think “track-changes” or “drop-box” history, but more structured.
You may have code, documentation, data, TODO lists, and more associated with a project.
To create a repository, you can start with your local computer first, or you can start with the remote (online) repository first.
Clone = create an exact copy locally
Git tracks changes to each file that it is told to monitor, and as the files change, you provide short labels describing what the changes were and why they exist (called “commits”).
The log of these changes (along with the file history) is called your git commit history. This means you can always go back to old copies!
Updates the copy of the repository on another machine (e.g. on GitHub) so that it has the most recent changes you’ve made to your machine.
Updates your local copy of the repository (the copy on your computer) with the files that are “in the cloud” (on GitHub).
Occur when you make changes to the same line as a collaborator either at the same time, or without starting from the same “state”.
Starting a new project/local repo
Starting a new project/local repo
Working with an existing local repo
Connect GitHub to RStudio
Work in your terminal or an .Rscript for this…
Enter password or token: Paste PATYou should be good to go! Let’s verify.
Always pull before you start working and always push after you are done working!
In general, if you follow the workflow for an existing local repo exactly, you only have problems if two of you are making local changes to the same line in the same file at the same time.
If you are working with collaborators in real time, pull, commit, and push often.
Git commits lines – lines of code, lines of text, etc.
Creating your STAT 331 /531 portfolio repository
Fork the STAT331_portfolio_template repository
Do not save your project in the same folder as your STAT331.Rproj!!!!
Here are some options:
Change the reflection_template.qmd file!
Were you unsuccessful? You likely need to configure your git!
git config --global user.name "Laura Smith"
git config --global user.email lsmith@example.com